﻿using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace IronBefunge.Core.Tests
{
	[TestClass]
	public sealed class ParserTests
	{
		[TestMethod]
		public void GetCellsWithMultipleLinesWithNoValues()
		{
			var lines = new string[] { "    ", string.Empty, "                   " };
			var cells = new Parser(lines).Parse();
			Assert.AreEqual(0, cells.Count);
		}

		[TestMethod]
		public void GetCellsWithMultipleLinesWithValues()
		{
			var lines = new string[] { "   <   ^#:  9              ", " ^ < ", " 3 5 :" };
			var cells = new Parser(lines).Parse();
			Assert.AreEqual(10, cells.Count);
			Assert.IsTrue(cells.Contains(new Cell(new Point(0, 3), '<')));
			Assert.IsTrue(cells.Contains(new Cell(new Point(0, 7), '^')));
			Assert.IsTrue(cells.Contains(new Cell(new Point(0, 8), '#')));
			Assert.IsTrue(cells.Contains(new Cell(new Point(0, 9), ':')));
			Assert.IsTrue(cells.Contains(new Cell(new Point(0, 12), '9')));
			Assert.IsTrue(cells.Contains(new Cell(new Point(1, 1), '^')));
			Assert.IsTrue(cells.Contains(new Cell(new Point(1, 3), '<')));
			Assert.IsTrue(cells.Contains(new Cell(new Point(2, 1), '3')));
			Assert.IsTrue(cells.Contains(new Cell(new Point(2, 3), '5')));
			Assert.IsTrue(cells.Contains(new Cell(new Point(2, 5), ':')));
		}

		[TestMethod]
		public void GetCellsWithSingleLineWithNoValues()
		{
			var lines = new string[] { "    " };
			var cells = new Parser(lines).Parse();
			Assert.AreEqual(0, cells.Count);
		}

		[TestMethod]
		public void GetCellsWithSingleLineWithValues()
		{
			var lines = new string[] { "   <   ^#:  9              " };
			var cells = new Parser(lines).Parse();
			Assert.AreEqual(5, cells.Count);
			Assert.IsTrue(cells.Contains(new Cell(new Point(0, 3), '<')));
			Assert.IsTrue(cells.Contains(new Cell(new Point(0, 7), '^')));
			Assert.IsTrue(cells.Contains(new Cell(new Point(0, 8), '#')));
			Assert.IsTrue(cells.Contains(new Cell(new Point(0, 9), ':')));
			Assert.IsTrue(cells.Contains(new Cell(new Point(0, 12), '9')));
		}

		[TestMethod]
		public void ParseWithNullArray()
		{
			var cells = new Parser(null).Parse();
			Assert.AreEqual(0, cells.Count);
		}

		[TestMethod]
		public void ParseWithNullLine()
		{
			var cells = new Parser(new string[] { " ^ < ", null, " 3 5 :" }).Parse();
			Assert.AreEqual(5, cells.Count);
		}
	}
}
